<template>
  <div>
    <div class="name">{{data.name}}</div>
    <div style="margin-top: 10px;">
      <div class="for-icon">
        <div>
          <span>分类：</span>
          <span style="color: #0ec5a5;">{{data.type_name||data.type}}</span>
        </div>
        <div>
          <i></i>
          <span>{{data.time}}</span>
        </div>
        <div>
          <i></i>
          <span>{{data.views}}</span>
        </div>

        <div>
          <i></i>
          <span>{{data.collect}}</span>
        </div>
        <div class="save">
          <span v-if="isSave==0" @click="addSave">收藏</span>
          <span v-else @click="cancelSave">取消收藏</span>
        </div>
      </div>
    </div>
    <div style="margin-right: 15px;display: flex;">
      <div style="margin:auto">
        <!-- <img style="width: 100%; height: 100%"  :src="item" alt=""> -->
        <el-image :src="data.img" :preview-src-list="[data.img]"></el-image>
      </div>
    </div>
    <div class="refer">
      <div>
        <div style="margin-left: 28px;">{{data.summary}}</div>
      </div>
      <div style="margin-left: 28px;" v-html="data.content"></div>
    </div>
  </div>
</template>

<script>
import { meatyAddSave, isMeatyAddSave, meatyCancelSave } from "@/api/home/api";
export default {
  
  data() {
    return {
      user: JSON.parse(localStorage.getItem("user")),
      data: {},
      isSave: 0
    };
  },
  watch: {
    // $route(){
    //   this.getList()
    // }
  },
  created() {
    this.getList();
    this.isMeatyAddSave();
  },
  methods: {
  
   
    getList() {
      this.data = JSON.parse(this.$route.query.details);
    },
    isMeatyAddSave() {
      let query = {
        u_id: this.user.id,
        m_id: this.data.id
      };
      isMeatyAddSave(query).then(res => {
        let data = res.data;
        this.isSave = data.isSave;
      });
    },
    addSave() {
      let query = {
        u_id: this.user.id,
        m_id: this.data.id
      };
      meatyAddSave(query).then(res => {
        let data = res.data;
        if (data == "ok") {
          this.isSave = 1;
          this.$message.success("收藏成功");
        }
      });
    },
    cancelSave() {
      let query = {
        u_id: this.user.id,
        m_id: this.data.id
      };
      meatyCancelSave(query).then(res => {
        let data = res.data;
        if (data == "ok") {
          this.isSave = 0;
          this.$message.success("取消成功");
        }
      });
    }
  }
};
</script>

<style scoped>
.name {
  font-size: 24px;
  font-weight: bold;
}
.for-icon {
  display: flex;
}
.for-icon {
  height: 20px;
  color: #b2b1b1;
  font-size: 12px;
  border-bottom: 1px solid #e5e5e5;
  padding-bottom: 6px;
  padding-top: 8px;
}
.for-icon > div {
  margin-right: 20px;
  cursor: pointer;
}

.for-icon > div:nth-child(2) > i {
  padding: 2px 12px;
  margin-right: 4px;
  background: url("../../../assets/icon/spirit.png") 0 -266px;
}
.for-icon > div:nth-child(3) > i {
  padding: 2px 12px;
  margin-right: 4px;
  background: url("../../../assets/icon/spirit.png") 0 -173px;
}
.for-icon > div:nth-child(4) > i {
  padding: 2px 12px;
  margin-right: 4px;
  background: url("../../../assets/icon/spirit.png") 0 -216px;
}
.save {
  margin-left: auto;
}
.save > span {
  margin-left: 10px;
  font-size: 14px;
}
.save > span:hover {
  color: rgb(15, 196, 161);
}
.refer {
  margin-top: 30px;
  margin-right: 15px;
  border-bottom: 1px solid rgb(82, 79, 79);
  padding-bottom: 30px;
}
.refer > div {
  margin-bottom: 20px;
}
.refer .title {
  font-size: 18px;
  padding-bottom: 10px;
  margin-top: 10px;
  font-weight: bold;
}
.refer .title:before {
  content: "";
  display: inline-block;
  margin-right: 10px;
  height: 16px;
  width: 16px;
  vertical-align: top;
  background: rgb(15, 196, 161);
}
</style>